package com.lanyuan.task;

import com.lanyuan.util.PropertiesUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractTask {

    private static final Logger log = LoggerFactory.getLogger(AbstractTask.class);

    public abstract void schedule();

    protected void execute() {
        if ("true".equals(PropertiesUtils.findPropertiesKey("upload-file-path"))) {
            return;
        }

        log.info("[定时任务(" + getName() + ")] - 开始");
        long timestamp = System.currentTimeMillis();
        try {
            doExecute();
        } catch (Exception e) {
            log.error("[定时任务(" + getName() + ")] - 异常：" + e.getMessage(), e);
        }
        log.info("[定时任务(" + getName() + ")] - 完成(" + (System.currentTimeMillis() - timestamp) + "ms)");
    }

    protected abstract void doExecute();

    protected abstract String getName();

}
